package cn.com.css.taxInspection.common.job.task;

import cn.com.css.taxInspection.attention.entity.CaseAjxxRelation;
import cn.com.css.taxInspection.attention.entity.JaajxxStatuschangeEntity;
import cn.com.css.taxInspection.attention.entity.JaajxxYjqlsjEntity;
import cn.com.css.taxInspection.attention.service.CaseAjxxRelationService;
import cn.com.css.taxInspection.attention.service.JaajxxStatuschangeService;
import cn.com.css.taxInspection.attention.service.JaajxxYjqlsjService;
import cn.com.css.taxInspection.gt3.entity.JcAjxxEntity;
import cn.com.css.taxInspection.gt3.service.JcAjxxService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 设置积案预计清理时间小于等于当前设为失效状态  每月1号
 */
@Component("yjqlsjTask1")
public class YjqlsjTask1 {
	private Logger logger = LoggerFactory.getLogger(getClass());
	@Resource
	private JaajxxYjqlsjService jaajxxYjqlsjService;

	public void run(String params) {
		logger.info("进入定时任务yjqlsjTask1，设置积案预计清理时间小于等于当前设为失效状态  每月1号定时任务开始");
		LambdaQueryWrapper<JaajxxYjqlsjEntity> queryWrapper = Wrappers.lambdaQuery();
		List<JaajxxYjqlsjEntity> dataList = jaajxxYjqlsjService.list(queryWrapper);
		List<String> ids  = new ArrayList<>();
		//2.根据获取的积案案件编号或者jcajxxuuid 去查询库查询当前案件，
		// 并判断当前案件状态与积案的案件状态如果不一致写入小助手数据库表中
		Date currentDate = new Date();
		for (JaajxxYjqlsjEntity obj:dataList) {
			Date objDate = obj.getYjqlTime();
			if(!objDate.after(currentDate)){
				ids.add(obj.getId());
			}
		}
		//设置为失效状态
		UpdateWrapper<JaajxxYjqlsjEntity> updateWrapper = new UpdateWrapper<>();
		updateWrapper.in("id", ids);
		updateWrapper.set("UPDATE_TIME", new Date());
		updateWrapper.set("YXBZ",'N');
		jaajxxYjqlsjService.update(updateWrapper);
		logger.info("进入定时任务yjqlsjTask1，设置积案预计清理时间小于等于当前设为失效状态  每月1号定时任务结束");
	}

}
